/**
 * $Revision: 1.1 $
 * $Date: 2010/06/28 07:02:23 $
 *
 * Copyright (C) 2006 Jive Software. All rights reserved.
 *
 * This software is published under the terms of the GNU Lesser Public License (LGPL),
 * a copy of which is included in this distribution.
 */

package org.jivesoftware.spark;

import org.jivesoftware.Spark;
import org.jivesoftware.spark.ui.ChatInputEditor;
import org.jivesoftware.spark.util.ResourceUtils;
import org.jivesoftware.spark.util.SwingWorker;

import cn.newgrand.netcall.advertisement.AdvertisementManager;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.UIManager;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.KeyListener;

/**
 * Creates a Firefox Search type box that allows for icons inside of a textfield. This
 * could be used to build out your own search objects.
 */
public class ChatAreaSendField extends JPanel {
	 private ChatInputEditor textField;
//    private JButton button;
//    private JPanel adChatBottom;
    final JScrollPane pane;

    /**
     * Creates a new IconTextField with Icon.
     *
     * @param text the text to use on the button.
     */
    public ChatAreaSendField(String text) {
        setLayout(new GridBagLayout());
        
        setBackground((Color)UIManager.get("TextPane.background"));
        textField = new ChatInputEditor();
//        textField.set
//        textField.setBorder(null);
//        setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, Color.lightGray));
        setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, (Color)UIManager.get("chatRoom.text.pane.border")));
//        button = new JButton();
        
        if (Spark.isMac()) {
//            button.setContentAreaFilled(false);
        }

//        ResourceUtils.resButton(button, text);

//        add(button, new GridBagConstraints(1, 0, 1, 2, 0.0, 1.0, GridBagConstraints.PAGE_END, GridBagConstraints.VERTICAL, new Insets(2, 0, 0, 2), 0, 0));

//        button.setVisible(true);
        
        pane = new JScrollPane(textField);
        pane.setBorder(null);
        pane.setPreferredSize(new Dimension(422,60));
        setMinimumSize(new Dimension(422,60));
//        pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        add(pane, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(2, 2, 2, 2), 0, 0));
//        button.setEnabled(false);
        
//        //聊天窗体底部添加广告面板
//        SwingWorker swingWorker =  new SwingWorker() {
//        	public Object construct() {
//        		try{
//        			adChatBottom = AdvertisementManager.getInstance().getAdChatBottom();
//        	        add(adChatBottom, new GridBagConstraints(0, 1, 1, 1, 1.0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
//        			return true;
//        		}catch (Exception e) {
//					// TODO: handle exception
//        			e.printStackTrace();
//        			return false;
//				}
//        	}
//        	 public void finished() {
//                 
//             }
//        };
//        swingWorker.start();
        
        
    }

//    public JButton getButton() {
//        return button;
//    }
//
//    public void showSendButton(boolean show) {
//        button.setVisible(show);
//    }
//
//    public void enableSendButton(boolean enabled) {
//        button.setEnabled(enabled);
//    }


    /**
     * Sets the text of the textfield.
     *
     * @param text the text.
     */
    public void setText(String text) {
        textField.setText(text);
    }

    /**
     * Returns the text inside of the textfield.
     *
     * @return the text inside of the textfield.
     */
    public String getText() {
        return textField.getText();
    }

    public ChatInputEditor getChatInputArea() {
        return textField;
    }
    
    public JScrollPane getScrollPane(){
    	return pane;
    }

}








